﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class Admin_ViewCustomerProfile : System.Web.UI.Page
{
    int CID;
    SqlConnection cnn;
    SqlCommand cmd;
    SqlDataReader dread;

    protected void Page_Load(object sender, EventArgs e)
    {
        CID = Int32.Parse(Request.QueryString["CustID"].ToString());
        cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["OPOConnectionString"].ToString());
        cnn.Open();
        cmd = new SqlCommand("Select * from Customer where CustID = '" + CID + "'", cnn);
        dread = cmd.ExecuteReader();
        if (!IsPostBack)
        {
            if (dread.Read())
            {
                if (dread.GetString(9) == "Enable")
                {
                    rdlStatus.SelectedIndex = 0;
                }
                else
                    rdlStatus.SelectedIndex = 1;
            }
        }
    }

    protected void imgbUpdate_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            dread.Close();
            cmd = new SqlCommand("Update Customer Set Cust_Status = @Cust_Status where CustID= '" + CID + "'", cnn);
            cmd.Parameters.Add(new SqlParameter("@Cust_Status", SqlDbType.NVarChar, 50));
            cmd.Parameters["@Cust_Status"].Value = rdlStatus.SelectedItem.ToString();
            cmd.ExecuteNonQuery();

            ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "ShowMessage()", true);
        }
        catch(Exception c)
        {
            MessageDialog.MessDialog(c.Message,this);
        }
    }

    protected void imgbBack_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("Customer_Management.aspx");
    }
}